/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lestr.udm.core.impl.types;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Scanner;
import org.lestr.udm.core.api.IDataType;
import org.lestr.udm.core.util.BasicDataTypes;

/**
 *
 * @author pibonnin
 */
public class BooleanDataType implements IDataType {


    public static IDataType instance = new BooleanDataType();


    @Override
    public String getId() {
        return "binary";
    }


    @Override
    public IDataType getParentType() {
        return BasicDataTypes.BINARY;
    }


    @Override
    public Object readValue(InputStream stream) {
        return new Scanner(stream).nextBoolean();
    }


    @Override
    public InputStream writeValue(Object value) {
        return new ByteArrayInputStream(new byte[]{((Boolean) value ? (byte) 1 : (byte) 0)});
    }


}

